<template>
    <div class="all_nav">

        <div class="all_nav_son">

            <div class="div_logo" @mouseenter="handleOut()">
                <!-- https://cdn.cnbj1.fds.api.mi-img.com/mi.com-assets/shop/img/logo-mi2.png -->
                <div class="logo_img">
                    <img src="https://cdn.cnbj1.fds.api.mi-img.com/mi.com-assets/shop/img/logo-mi2.png" alt="">
                </div>

            </div>
            <div class="div_nav">
                <ul class="mouse_main">
                    <div v-for="(data, index) in datalist" :key="data">
                        <li @mouseenter="handleMouse(index)">{{ data }}</li>
                    </div>
                    <router-link custom to="/shop/service" v-slot="{ navigate }">
                        <div>
                            <li @click="navigate" @mouseenter="handleOut()">服务中心</li>
                        </div>
                    </router-link>
                    <router-link custom to="/shop/community" v-slot="{ navigate }">
                        <div>
                            <li @click="navigate" @mouseenter="handleOut()">社区</li>
                        </div>
                    </router-link>
                </ul>

            </div>
            <div class="header_serach">

                <el-input v-model="input" placeholder="请输入商品信息" clearable />

                <div class="header_submit" @click="handleSearch">
                    <i class="iconfont icon-icon-test12 "></i>
                </div>
            </div>
        </div>
        <ul class="mouse_enter" @mouseleave="handleLeave()" v-if="isShow">
            <div v-for="(item, index) in store.SeachList" :key="index">
                <li v-if="countIndex === index">
                    <div class="nav_item">
                        <ul>
                            <li v-for="img in item" :key="img">
                                <div class="item_son">
                                    <img :src="img.url" alt="" style="width: 150px;height: 100px;">
                                </div>
                                <p class="item_p_1">{{ img.title }}</p>
                                <p class="item_p_2">{{ img.price }}元起</p>
                            </li>
                        </ul>
                    </div>
                </li>
            </div>
        </ul>
    </div>
</template>
<script setup>
import { ref } from 'vue'
import useSearch from '../store/Search';
const store = useSearch()
const datalist = ref(["Xiaomi手机", "Redmi手机", "电视", "笔记本", "家电", "平板", "路由"])

const input = ref('')
const countIndex = ref(-1)
const isShow = ref(false)
// 调用pinia里面的方法
store.getSeachList()

const handleMouse = (index) => {
    setTimeout(() => {
        isShow.value = true
    }, 600)
    countIndex.value = index
}

const handleSearch = () => {
    console.log(input.value)
}
const handleOut = () => {
    countIndex.value = 7
}
const handleLeave = () => {
    setTimeout(() => {
        countIndex.value = -1
        isShow.value = false

    }, 500)
}
</script>
<style lang="scss" scoped>
* {
    margin: 0;
    padding: 0;
}

.all_nav {
    width: 100%;
    position: relative;

    .all_nav_son {
        width: 1200px;
        height: 120px;
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .div_logo {
            width: 100px;
            height: 120px;
            display: flex;
            align-items: center;

            .logo_img {

                img {
                    width: 60px;
                    height: 60px;
                }
            }
        }

        .div_nav {
            width: 700px;
            height: 100px;

            .mouse_main {
                list-style: none;
                display: flex;
                justify-content: space-around;

                li {
                    width: auto;
                    height: 120px;
                    line-height: 100px;
                    cursor: pointer;
                }

                li:hover {
                    color: #ff6a00;
                }
            }
        }

        .header_serach {
            float: right;
            width: 250px;
            height: 50px;
            display: flex;

            .el-input {
                width: 200px;
                height: 50px;
            }

            .header_submit {
                width: 50px;
                height: 50px;
                border: 1px solid #ccc;
                display: flex;
                justify-content: center;
                align-items: center;
                cursor: pointer;
                border-radius: 5px;
                box-sizing: border-box;

                i {
                    font-size: 25px;
                    font-weight: 900;
                }
            }

            .header_submit:hover {
                border: 1px solid orangered;
                background: orangered;
                color: white;
            }

        }
    }

    .mouse_enter {
        position: absolute;
        left: 0;
        width: 100%;
        height: 200px;
        list-style: none;
        border-top: 1px solid #ccc;

        li {
            width: 1200px;
            margin: 0 auto;
            height: 200px;
            z-index: 10000;
            background: white;

            .nav_item {
                ul {
                    display: flex;
                    list-style: none;

                    li {
                        flex: 1;
                        display: flex;
                        align-items: center;
                        flex-direction: column;
                        cursor: pointer;

                        .item_son {
                            z-index: 1000;
                            width: 150px;
                            height: 100px;
                            margin-top: 30px;
                            overflow: hidden;

                        }

                        .item_p_1 {
                            font-size: 13px;
                            font-weight: 400;
                            margin-top: 10px;
                        }

                        .item_p_2 {
                            margin-top: 5px;
                            color: #ff6a00;
                            font-size: 10px;
                        }
                    }
                }
            }
        }

    }
}
</style>